<template>
    <div class="about">
		<!-- <banner isHome="true"></banner> -->
        <div class="site-content">
            <div class="content-warp">
                <div class="about-me about-info">
                    <section-title id="Guestbook"><span>❤</span>管理社团</section-title>
                    <div class="info-card">
						<el-card>{{club.name}}全部成员</el-card>
						<el-button @click="post()">职位管理</el-button>
						<el-button @click="department()">部门管理</el-button>
						<el-button @click="race()">比赛管理</el-button>
						<el-button @click="article()">文章管理</el-button>
						<el-button @click="auditUser()">审核人员</el-button>
						<el-table  :data="clubUser">
							<el-table-column label="序号" align="center" type="index" />
							<el-table-column label="名字" align="center" prop="name" />
							<el-table-column label="手机号码" align="center" prop="telephone" />
							<el-table-column label="部门" align="center" prop="department" />、
							<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
							  <template slot-scope="scope">
							    <el-button
							      size="mini"
							      type="text"
							      icon="el-icon-edit"
								  v-if="scope.row.my != true"
							      @click="alter(scope.row.id, scope.row.departmentId, scope.row.postsId, scope.row.clubId)"
							    >修改职位</el-button>
							    <el-button
							      size="mini"
							      type="text"
							      icon="el-icon-delete"
								  v-if="scope.row.my != true"
							      @click=""
							    >移除社团</el-button>
							  </template>
							</el-table-column>
						</el-table>
						<pagination
						  v-show="total>0"
						  :total="total"
						  :page.sync="queryParams.pageNum"
						  :limit.sync="queryParams.pageSize"
						  @pagination="getData()"
						/>
						<el-dialog title="修改职位" :visible.sync="open" width="500px" append-to-body>
						  <el-form ref="form" :model="user" label-width="80px">
						    <el-form-item label="修改" >
								<el-select v-model="valueDep" clearable placeholder="请选择部门">
								  <el-option
									v-for="item in clubDep"
									:key="item.id"
									:label="item.name"
									:value="item.id">
								  </el-option>
								</el-select>
								<el-select v-model="valuePosts" clearable placeholder="请选择职位">
								  <el-option
									v-for="item in posts"
									:key="item.id"
									:label="item.name"
									:value="item.id">
								  </el-option>
								</el-select>
						    </el-form-item>
						  </el-form>
						  <div slot="footer" class="dialog-footer">
						    <el-button type="primary" @click="submit()">确 定</el-button>
						    <el-button @click="cancel">取 消</el-button>
						  </div>
						</el-dialog>
						
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
	import sectionTitle from '@/components/section-title'
	import { 
		getAllPosts, getCLubDep, insertRoleUser, 
		getClubUserList, getUserById } from '../../api/manager'
	export default {
	    name: "manager",
	    data() {
	        return {
				clubUser: [],
				club: [],
				hasNextPage: true,
				open: false,
				user: [],
				clubDep: [],
				posts: [],
				valueDep: '',
				valuePosts: '',
				userId: '',
				clubId: '',
				// 查询参数
				queryParams: {
				  pageNum: 1,
				  pageSize: 10
				},
				total: 0
	        }
	    },
	    components: {
			sectionTitle
	    },
	    methods: {
			async getData() {
				let data = await getClubUserList({
					pageNum: this.queryParams.pageNum,
					pagesize: this.queryParams.pageSize
				})
				this.clubUser = data.user
				this.club = data.club
				this.total = data.total
			},
			cancel() {
			  this.open = false;
			},
			// 修改职位获取信息接口
			async alter(userId, departmentId, postsId, clubId) {
				let data = await getUserById(userId)
				let x = 0
				let dep = await getCLubDep(x)
				let posts = await getAllPosts()
				this.clubDep = dep.department
				this.posts = posts.posts
				this.user = data.user
				this.open = true
				this.valueDep = departmentId
				this.valuePosts = postsId
				this.userId = userId,
				this.clubId = clubId
			},
			// 修改接口
			async submit() {
				await insertRoleUser({
					userId: this.userId,
					postsId: this.valuePosts,
					clubId: this.clubId,
					departmentId: this.valueDep
				})
				this.currPage = 1
				this.open = false
				this.getData()
			},
			post() {
				this.$router.push("/posts")
			},
			department() {
				this.$router.push("/department")
			},
			race() {
				this.$router.push("/raceManager")
			},
			article() {
				this.$router.push("/articleManager")
			},
			auditUser() {
				this.$router.push("/userManager")
			}
		},
	    mounted() {
			this.getData()
	    }
	}
</script>

<style scoped lang="less">
    .about {
        padding-top: 40px;
    }
	
	.list-group-striped > .list-group-item {
		border-left: 0;
		border-right: 0;
		border-radius: 0;
		padding-left: 0;
		padding-right: 0;
	}
	.list-group-item {
		border-bottom: 1px solid #e7eaec;
		border-top: 1px solid #e7eaec;
		margin-bottom: -1px;
		padding: 11px 0;
		font-size: 13px;
	}
	.pull-right {
		float: right !important;
	}
	.focusinfo {
	    position: relative;
	    max-width: 800px;
	    padding: 0 10px;
	    top: 40%;
	    left: 50%;
	    transform: translate(-50%,-50%);
	    -webkit-transform: translate(-50%,-50%);
	    text-align: center;
	    img {
			margin-top: 100px;
	        width: 80px;
	        height: 80px;
	        border-radius: 50%;
	        border: 3px solid rgba(255, 255, 255, 0.3);
	    }
	}

    .content-warp {
        margin-top: 80px;

        .about-info {
            margin: 30px 0;

            span {
                color: red;
                margin-right: 10px;
            }

            .info-card {
                min-height: 100px;
                padding: 20px;
                border-radius: 3px;
                margin: 30px 0 50px 0;
                box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
                p{
                    line-height: 1.7rem;
                }
            }
        }
        .contactForm{
			text-align: center;
            width: 100%;
            padding: 20px;
            .form-item{
                align-items: center;
                display: flex;
                &:not(:last-child){
                    margin-bottom: 20px;
                }
                label{
                  width: 80px;
                }
                .v{
                    min-height: 40px;
                    line-height: 20px;
                    border-radius: 3px;
                    padding: 2px 10px;
                    outline:none;
                    border: 1px solid #8fd0cc;
                    width: 100%;
                    resize: vertical;
                }
                button{
                    width: 100px;
                    height: 40px;
                    border-radius: 3px;
                    outline:0;
                    border-style: none;
                    cursor: pointer;
                    background-color: #409eff;
                    color: white;
                    &:hover{
                        opacity: 0.8;
                    }
                }
            }
        }
    }
	
	.more{
	    margin: 50px 0;
	    .more-btn{
	        width: 100px;
	        height: 40px;
	        line-height: 40px;
	        text-align: center;
	        color: #ADADAD;
	        border: 1px solid #ADADAD;
	        border-radius: 20px;
	        margin: 0 auto;
	        cursor: pointer;
	        &:hover{
	            color: #8fd0cc;
	            border: 1px dashed #8fd0cc;
	        }
	    }
	}

    /*******/
    @media (max-width: 800px) {
        .content-warp {
            margin-top: 0;
        }
    }
</style>